package com.xywh.emergency_outbound.mvp.ui.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.xywh.emergency_outbound.R;
import com.xywh.emergency_outbound.mvp.ui.entity.Tab2;

import java.util.List;


public class Tab2Adapter extends BaseQuickAdapter<Tab2.DataBean, BaseViewHolder> {

    private Context mContext;
    private IConfirmReceipt mIConfirmReceipt;

    public Tab2Adapter(Context context, @Nullable List<Tab2.DataBean> data, IConfirmReceipt iConfirmReceipt) {
        super(R.layout.item_tab2, data);
        this.mContext = context;
        this.mIConfirmReceipt = iConfirmReceipt;
    }

    @Override
    protected void convert(BaseViewHolder helper, Tab2.DataBean item) {
        //GlideUtil.loadImage(mContext,item.getImg(),helper.getView(R.id.img_head));

        helper.setText(R.id.tv_order_number, "订单编号：" + item.getOutStorageListBatchId());
        helper.setText(R.id.tv_status, item.getTransferStatusName());
        helper.setText(R.id.tv_title, item.getEmgTransferItems().get(0).getMaterialName());
        helper.setText(R.id.tv_order_time, "下单时间：" + item.getInsertDateTime());
        helper.setText(R.id.tv_outbound_time, "出库时间：" + item.getOutstorageDateTime());
        //TransferStatus 1 取消  2 可以确认
        Button btn_confirm = helper.getView(R.id.btn_confirm);
        Button btn_cancel = helper.getView(R.id.btn_cancel);
        btn_confirm.setVisibility(View.GONE);
        btn_cancel.setVisibility(View.GONE);

//        LogUtils.debugEInfo("订单编号：" + item.getOutStorageListBatchId() + " TransferStatus=" + item.getTransferStatus());

        if (item.getTransferStatus() == 1) {
            btn_cancel.setVisibility(View.VISIBLE);
        } else if (item.getTransferStatus() == 2) {
            btn_confirm.setVisibility(View.VISIBLE);
        }

        helper.setOnClickListener(R.id.btn_confirm, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mIConfirmReceipt.confirmReceipt(item);
            }
        });
        helper.setOnClickListener(R.id.btn_cancel, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mIConfirmReceipt.cancelReceipt(item);
            }
        });
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public interface IConfirmReceipt {
        void confirmReceipt(Tab2.DataBean dataBean);

        void cancelReceipt(Tab2.DataBean dataBean);
    }

}
